package com.example.sys.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;
import java.util.List;

import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.example.sys.entity.enums.GradeEnum;
import com.example.sys.entity.enums.StyleEnum;
import com.example.sys.entity.types.ArticleTypeHandle;
import com.example.sys.entity.types.DelimitedStringNotNullTypeHandler;
import com.example.sys.entity.types.DelimitedStringTypeHandler;
import com.example.sys.entity.types.UserInfoTypeHandler;
import com.github.yulichang.annotation.EntityMapping;
import com.github.yulichang.annotation.FieldMapping;
import com.github.yulichang.annotation.MPJMappingApply;
import com.github.yulichang.annotation.MPJMappingCondition;
import io.swagger.annotations.ApiModel;
import lombok.*;
import lombok.experimental.Accessors;
import org.apache.ibatis.type.EnumOrdinalTypeHandler;
import org.apache.ibatis.type.JdbcType;

/**
 * <p>
 *
 * </p>
 *
 * @author ZhengDing
 * @since 2022-01-28 09:31:35
 */
@Data
@Accessors(chain = true)
@TableName(value = "xf_article", autoResultMap = true)
@ApiModel(value = "Article对象", description = "")
@NoArgsConstructor
@AllArgsConstructor
public class Article implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;
    
    @TableField("title")
    private String title;
    
    @TableField("content")
    private String content;
    
    @TableField("create_by")
    private Integer createBy;
    
    @TableField(exist = false)
    @EntityMapping(thisField = "createBy", joinField = "id")
    private User createByObject;
    
    //@TableField(value = "create_by", jdbcType = JdbcType.INTEGER, javaType = true, typeHandler = UserInfoTypeHandler.class)
    //private User createBy;
    
    //@TableField(value = "create_by", typeHandler = UserInfoTypeHandler.class)
    //private User createBy;
    
    private Integer parentId;
    
    @TableField(exist = false)
    @EntityMapping(thisField = "parentId", joinField = "id")
    private Article parent;
    
    @TableField(exist = false)
    @EntityMapping(thisField = "id", joinField = "parentId")
    private List<Article> children;
    
    @TableField(exist = false)
    @EntityMapping(thisField = "id", joinField = "parentId",
            condition = {
                    @MPJMappingCondition(column = "grade", value = "1000")},
            apply = {
                    @MPJMappingApply("id > 100")})
    private List<Article> childrenByGrade1000;
    
    @TableField(exist = false)
    @FieldMapping(tag=Article.class, thisField = "id", joinField = "parentId", select = "id")
    private List<Integer> childIds;
    
    @TableField(value = "category", typeHandler = ArticleTypeHandle.class)
    private String category;
    
    @TableField(value = "langs", typeHandler = DelimitedStringNotNullTypeHandler.class)
    private List<String> langs;
    
    @TableField(value = "grade")
    private GradeEnum grade;
    
    //@TableField(value = "style", typeHandler = EnumOrdinalTypeHandler.class)
    //private StyleEnum style;
    
    
    public static final String ID = "id";
    
    public static final String TITLE = "title";
    
    public static final String CONTENT = "content";
    
    public static final String CREATE_BY = "create_by";
    
    public static final String CATEGORY = "category";
    
}
